import { createRouter, createWebHashHistory } from 'vue-router'
import routes from './routes'

const router = createRouter({
  history: createWebHashHistory(),
  routes
})

// 路由守卫
router.beforeEach((to,from,next)=>{
  // 获取token
  const token = window.localStorage.getItem('token');

  if(to.name!=='login' && !token){
      next({name:'login'})
  }else{
      next()
  }


})


export default router
